Dialog Box Commands


Authors make adjustments to graphic interface of their applications, but there are some standard Windows dialog boxes that are used by all applications.
MMB introduces this standard dialog boxes, available through it's script language:

  •   Message Box
  •   Open File dialog box
  •   Save File dialog box
  •   Browse for Folder dialog box
  •   Color Picker dialog box

 

Message("String","Variable")
Description
 


Displays Message box with OK button and exclamation mark.
Use first parameter to set message you want to display:

Hello from MMB

Second parameter can be used to show a value of any string or numerical variable. This is especially useful when debugging a program, to check current variable value:

UserFile$

Here's an example of a Message box:

Code Examples
 

**Show Message box without variables:
Message("Hello from MMB", "")

**Show Message box with numerical variable as 2nd parameter:
year=2004
Message("
Selected year: ", "year")

**Show Message box with string variable as 2nd parameter:
name$='Sam'
Message("
Welcome, ","name$")

**Show Message box with 2 string variables as parameters:
greeting$='Hello,'
name$='Peter'

Message("
greeting$","name$")

Additional Info
 
Message box is displayed on top and project's window can't be used until user closes message box.

 

OpenFile("Filter","DefaulExt")
Description
 


Displays Open File dialog box. First parameter sets extension filter, default extension is specified as a second parameter.

Extension filter - sets what file formats will be displayed in a dialog box. MMB supports multiple masks, selectable through "Files of type" combobox inside Open File dialog box. Filter is set in a string as the first command parameter. Elements and their parts are separated using | character.

Mask element is comprised of label and extension:

MPEG Files (*.mpg) | *.mpg

Blue part is extension element label, green part is extension itself. They're separated with | character. You'll write another extension element behind this one, separating it again using | character. So extension filter will now look like this:

MPEG Files (*.mpg) | *.mpg| AVI Files (*.avi)| *.avi

When you're done adding extension elements, | character is needed at the end of parameter to signal MMB about it:

MPEG Files (*.mpg) | *.mpg| AVI Files (*.avi)| *.avi |

There. Line above represents first command parameter. It is also common to specify "All files" as the last extension element, giving users ability to see all files (turn filtering off). Here's how such version of first command parameter looks like:

MPEG Files (*.mpg) | *.mpg| AVI Files (*.avi)| *.avi | All Files (*.*) | *.* |

It is also possible to specify multiple extensions in one element, giving users ability to choose among similar file extensions (.mpg & .mpeg, .htm & html, .jpg & .jpeg...) . Use ; as an extension delimiter:

Movie Files (*.mpg,*.avi) | *.mpg ;*.avi| All Files (*.*)| *.* |

Default extension element, the one that will be used for file filtering when Open File dialog box appears, is set using second command parameter.

It's one of element extensions specified as the first parameter, for e.g.

*.mpg

Using multiple extensions in one element affects default extension too, so you will also use ; as extension delimiter:

*.mpg ;*.avi

Put into OpenFile command, parameters look like this:

OpenFile(" Movie Files (*.mpg,*.avi) | *.mpg ;*.avi| All Files (*.*)| *.* | "," *.mpg ;*.avi ")

Here's example of Open File dialog box, showing all files:

 

Once user selects file and clicks Open button (or double-clicks selected file), MMB fills OpenFile$ string variable with full folder path and file name of selected file.

Three constants also contain dialog box result:

<File> - contains the same data as OpenFile$ variable
CBK_OpenFile - contains selected file name without folder path
CBK_OpenDir - contains folder path without name of selected file

Code Examples
 

**Show Open File dialog box with filters for MP3, WAV, MID and MOD
**files with WAV as default filter
OpenFile(" MP3 Files (*.mp3)|*.mp3|WAVE Files (*.wav)|*.wav|MIDI Files (*.mid)|*.mid|MOD Files (*.mod)|*.mod|","*.wav")

**Show Open File dialog box with one filter for MP3, WAV, MID and MOD
**files, labeled "Sound Files"
OpenFile(" Sound Files (*.mp3,*.wav,*.mid,*.mod) |*.mp3;*.wav;*.mid;*.mod|","*.mp3;*.wav;*.mid;*.mod")

**Show Open File dialog box with filters for EXE and All files
**with EXE as default filter
OpenFile(" Executable Files (*.exe)|*.exe|All Files (*.*)|*.*|","*.exe")

**Show Open File dialog box with filters for HTML and all files
**with HTML as default filter. Result is displayed in message boxes
OpenFile(" HTML Files (*.htm)|*.htm|All Files (*.*)|*.*|","*.htm")
Message("Selected file in OpenFile$ variable: ","OpenFile$")
file$=<File>
Message("Selected file in <File> constant: ","file$")
file$=CBK_OpenFile
Message("Selected file name: ","file$")
folder$=CBK_OpenDir
Message("Folder path of selected file: ","folder$")

**Show Open File dialog box at defined position (source application directory in this case) and with filter for TXT files.  
Path$=<SrcDir>+'*.txt'
OpenFile("
TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||","Path$")

Additional Info
 
Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

SaveFile("Filter","DefualtExt")
Description
 


Displays Save File dialog box. First parameter sets extension filter, default extension is specified as a second parameter.

Extension filter - sets what file formats will be displayed in a dialog box. MMB supports multiple masks, selectable through "Files of type" combobox inside Save File dialog box. Filter is set in a string as first command parameter. Elements and their parts are separated using | character.

Mask element is comprised of a label and extension:

TXT Files (*.txt) | *.txt

Blue part is extension element label, green part is extension itself. They're separated with | character. You'll write another extension element behind this one, separating it again using | character. So extension filter will now look like this:

TXT Files (*.txt) | *.txt| LOG Files (*.log)| *.log

When you're done adding extension elements, | character is needed at the end of parameter to signal MMB about it:

TXT Files (*.txt) | *.txt| LOG Files (*.log)| *.log |

Line above represents first command parameter. It is also common to specify "All files" as the last extension element, giving users ability to see all files (turn filtering off). Here's how such version of first command parameter looks like:

TXT Files (*.txt) | *.txt| LOG Files (*.log)| *.log | All Files (*.*) | *.* |

It is also possible to specify multiple extensions in one element, giving users ability to choose among similar file extensions (.mpg & .mpeg, .htm & html, .jpg & .jpeg...) . Use ; as extension delimiter:

Text Files (*.txt,*.log) | *.txt ;*.log| All Files (*.*)| *.* |

Default extension element, the one that will be used for file filtering when Save File dialog box is displayed, is set using second command parameter.

It's one of element extensions specified in first parameter, for e.g.

*.txt

Using multiple extensions in one element affects default extension too, so you will also use ; as an extension delimiter:

*.txt ;*.log

Put into SaveFile command, parameters look like this:

SaveFile(" Text Files (*.txt,*.log) | *.txt ;*.log| All Files (*.*)| *.* | "," *.txt ;*.log ")

Here's example of Save File dialog box, showing all files:

 

Once user selects or writes file name and clicks Save button (or double-clicks selected file), MMB will fill OpenFile$ string variable with full folder path and file name of selected file.

Three constants also contain dialog box result:

<File> - contains the same data as OpenFile$ variable
CBK_OpenFile - contains selected file name without folder path
CBK_OpenDir - contains folder path without name of selected file

Code Examples
 

**Show Save File dialog box with filters for TXT and LOG
**files with TXT as default filter

SaveFile(" TXT Files (*.txt)|*.txt|LOG Files (*.log)|*.log|", "*.txt")

**Show Save File dialog box with one filter for TXT and LOG
**files, labeled "Text Files"
SaveFile(" Text Files (*.txt,*.log)|*.txt;*.log|", "*.txt;*.log")

**Show Save File dialog box with filters for TXT and All files
**with TXT as default filter
SaveFile(" TXT Files (*.txt)|*.txt|All Files (*.*)|*.*|","*.txt")

**Show Save File dialog box with filters for TXT and All files
**with TXT as default filter. Result is displayed in message boxes
SaveFile(" TXT Files (*.txt)|*.txt|All Files (*.*)|*.*|","*.txt")
Message("Selected file in OpenFile$ variable: ","OpenFile$")
file$=<File>
Message("Selected file in <File> constant: ","file$")
file$=CBK_OpenFile
Message("Selected file name: ","file$")
folder$=CBK_OpenDir
Message("Folder path of selected file: ","folder$")

**Show Save File dialog box at defined position (source application directory in this case) and with filter for TXT files.  
Path$=<SrcDir>+'*.txt'
OpenFile("
TXT Files (*.txt)|*.txt|All Files (*.*)|*.*||","Path$")

Additional Info
 
Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

BrowseForFolder("Prompt","StartFolder")
Description
 


Displays Browse for Folder dialog box. First parameter sets dialog description, second parameter sets starting (root) folder.

Both parameters are optional.

Dialog description - defines prompt that will be displayed in Browse for Folder dialog box. Usual prompt is:

Select folder:

Starting folder - sets root folder and disables browsing for upper folders. Default starting folder is:

My Computer

Here's an example of Browse for Folder dialog box:

 

Once user selects folder and clicks OK button, constant CBK_OpenDir will contain selected folder path.

Code Examples
 

**Show basic Browse for Folder dialog box:
BrowseForFolder("","" )

**Show Browse for Folder dialog box with custom prompt:
BrowseForFolder("Select Folder: ","" )

**Show Save File dialog box with filters for TXT and All files
**with TXT as default filter
SaveFile(" TXT Files (*.txt)|*.txt|All Files (*.*)|*.*|","*.txt")

**Show Browse for Folder dialog box with custom prompt
**and c:\ as starting folder

BrowseForFolder("Select Folder: ","c:\" )

**Show Browse for Folder dialog box with custom prompt
**and starting folder specified through string variables

prompt$='Select directory'
root$='c:\\'

BrowseForFolder("prompt$","root$"
)

Additional Info
 
Dialog box is displayed on top and project's window can't be used until user closes dialog box.

 

ColorPicker()
Description
 


Displays Color Picker dialog box. Uses no input parameters.


 

Once user selects color and clicks OK button, constant CBK_SelColor will contain selected color.

Color picking uses RGB ( Red, Green, Blue) system containing 3 components.

Each component can have one of 256 levels. Greater value of component increases color intensity. If you specify value 0, color component will not be used. Value 255 uses maximum color intensity.

Result of Color Picker is a comma-separated array of string values, each representing one RGB component (first: red, second: green, third: blue) in value range 0-255.

R,G,B
Result
128,5,64
 

R,G,B
Result
0,255,255
 

 

To retrieve color value, simply assign contents of CBK_SelColor to a string variable:

color$=CBK_SelColor

Returned color value looks like this:

119,230,95

Code Examples
 

**Show Color Picker dialog box:
ColorPicker( )

**Show Color Picker dialog box, retrieve and show selected color string:
ColorPicker( )
color$=CBK_SelColor
Message("Selected color is: ","color$")

Additional Info
 
Dialog box is displayed on top and project's window can't be used until user closes dialog box.


MMB Scripting Unleashed by Bokzy, 2003 :: All rights reserved :: http://www.bokzy.com